package com.servlet.listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * @Title: MySessionListener
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2023/12/26 11:20
 */
@WebListener
public class MySessionListener implements HttpSessionListener {

    /**
     * 监听session的创建
     * @param httpSessionEvent
     */
    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
        HttpSession session = httpSessionEvent.getSession();
        Object user = session.getAttribute("usersession");
        System.out.println("session创建"+user);
        System.out.println("session 已经创建了。。。");


    }

    /**
     * 监听session的销毁
     * @param httpSessionEvent
     */
    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
        HttpSession session = httpSessionEvent.getSession();
        Object user = session.getAttribute("usersession");
        System.out.println("session创建"+user);
        System.out.println("session 已经销毁了。。。");


    }
}
